﻿using System.Globalization;
using BugSense;
using Wulong.Phone.Qiushi.i18n;
using Wulong.Phone.Qiushi.ViewModels;
using Wulong.Phone.Utils;

namespace Wulong.Phone.Qiushi
{
    public partial class App
    {

        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            BugSenseHandler.Instance.Init(this, "52c1ffff");
            SetLocale();
            // Standard Silverlight initialization
            InitializeComponent();
        }

        private static void SetLocale()
        {
            int savedLang;
            var newCulture = new CultureInfo("zh-CN");
            if (!AppSettings.TryGetSetting("Lang", out savedLang))
                AppSettings.StoreSetting("Lang", (int) LangSupported.Chinese);
            else
                switch ((LangSupported) savedLang)
                {
                    case LangSupported.Auto:
                        newCulture = CultureInfo.CurrentCulture;
                        break;
                    case LangSupported.English:
                        newCulture = new CultureInfo("en-US");
                        break;
                    case LangSupported.Chinese:
                        newCulture = new CultureInfo("zh-CN");
                        break;
                }
            AppResources.Culture = newCulture;
        }
    }
}